﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using InformationExtraction.Interface;

namespace InformationExtraction
{
    class FileEnumerater
    {
        private IFileEnumerate fileEnumerator = null;
        private const string FILEPATTERN = "*.key";

        public List<DirectoryInfo> DirInfos
        {
            get;
            set;
        }

        public FileEnumerater(IFileEnumerate fe)
        {
            fileEnumerator = fe;
            DirInfos = new List<DirectoryInfo>();
        }

        public void Exec()
        {
            fileEnumerator.DoBeforeEnumerate();

            System.Console.WriteLine("File Directory:");
            foreach (DirectoryInfo d in DirInfos)
            {
                System.Console.WriteLine("    " + d.Name + "/");
            }
            System.Console.WriteLine("\n");

            
            foreach (DirectoryInfo d in DirInfos)
            {            
                foreach (FileInfo f in d.GetFiles(FILEPATTERN))
                {
                    System.Console.WriteLine("Extracting File: " + d.Name + "/" + f.Name);
                    fileEnumerator.DoForEachFile(f);
                }
            }

            fileEnumerator.DoWhenComplete();
        }

        public void SetOutput(string fileName)
        {
            fileEnumerator.SetOutputFile(fileName);
        }
    }
}
